package com.life.notes.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.life.notes.dao.SysMenuMapper;
import com.life.notes.dto.MenuQueryPara;
import com.life.notes.model.SysMenuEntity;
import com.life.notes.service.SysMenuService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description 权限业务实现
 * @Author Sans
 * @CreateTime 2019/9/14 15:57
 */
@Service("sysMenuService")
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenuEntity> implements SysMenuService {

    @Override
    public List<SysMenuEntity> listTreeMenu() {
        return this.baseMapper.selectList(null);
    }

    @Override
    public IPage<SysMenuEntity> listPage(MenuQueryPara filter) {
        Page<SysMenuEntity> page = new Page<>(filter.getPage(),filter.getLimit());
        return this.baseMapper.selectMenus(page, filter);
    }

    @Override
    public List<SysMenuEntity> list(MenuQueryPara filter) {
        return this.baseMapper.selectMenus(filter);
    }

    @Override
    public Integer saveMenu(SysMenuEntity para) {
        if (para.getId()!=null) {
            this.baseMapper.updateById(para);
        } else {
            this.baseMapper.insert(para);
        }
        return para.getId();
    }
}